//
//  XMOrderMeetingViewController.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/21.
//

#import "XMOrderMeetingViewController.h"
#import "XMOrderMeetingView.h"
#import "XMNetwork+mine.h"
#import "XMOrderDetailModel.h"
#import "XMMeetEvaluateViewController.h"

@interface XMOrderMeetingViewController ()<XMOrderMeetingViewDelegate>

@property (nonatomic, strong) XMOrderMeetingView *orderMeetingView;
@property (nonatomic, strong) XMOrderDetailModel *orderDetailModel;

@end

@implementation XMOrderMeetingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatUI];
}

- (void)creatUI {
    [self.view addSubview:self.orderMeetingView];
    [self getOrderDetailInfo];
}

- (void)getOrderDetailInfo {
    XMWeakSelf;
    [_Network getOrderDetailWithOrderId:_orderId
                                success:^(id  _Nonnull responseObject) {
        XMOrderDetailModel *orderDetailModel = [XMOrderDetailModel yy_modelWithJSON:responseObject[@"data"]];
        weakSelf.orderDetailModel = orderDetailModel;
        [weakSelf.orderMeetingView setContentWithOrderDetailModel:orderDetailModel];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

//评价
- (void)meetEvaluateAction {
    XMMeetEvaluateViewController *evaluateVC = [[XMMeetEvaluateViewController alloc] init];
    evaluateVC.orderDetailModel = self.orderDetailModel;
    [self.navigationController pushViewController:evaluateVC animated:YES];
}

//删除结束订单
- (void)meetDeleteAction {
    XMWeakSelf;
    [_Network deleteMeetingWithServiceId:_orderId
                                 success:^(id  _Nonnull responseObject) {
        weakSelf.meetEditBlock ? weakSelf.meetEditBlock() : nil;
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

//结束
- (void)meetOverWithOrderNo:(NSString *)orderNo {
    XMWeakSelf;
    [_Network meetOverWithOrderNo:orderNo
                          success:^(id  _Nonnull responseObject) {
        weakSelf.meetEditBlock ? weakSelf.meetEditBlock() : nil;
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

#pragma mark - Init
- (XMOrderMeetingView *)orderMeetingView {
    if (!_orderMeetingView) {
        _orderMeetingView = [[XMOrderMeetingView alloc] initWithFrame:self.view.bounds meetingType:_meetingType];
        _orderMeetingView.delegate = self;
    }
    return _orderMeetingView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
